- /* slominus.cpp by K.Tsuru */
- // function ID = 225 DRADIX, BRADIX
- /****************
- SLong class
- operator-() m-n
- ******************/
- #ifndef SN_H
- #include "sn.h"
- #endif
- SLong operator-(const SLong& m, const SLong& n){
- // check radix in LLSub and LLAdd
- // if(m.Radix() != n.Radix()) m.SetError(m.RADIX_ERR, "SL \'-\'", 202);
- //This function is also used in Knuth's divide of SInteger class.
- // if((m.Radix() != DRADIX)||(n.Radix() != DRADIX)) m.SetError(m.RADIX_ERR, "SL -", 202);
- int c, s = m.Sign(202) * n.Sign(202);
- SLong r(m.Type(), 0);
-
- if( !s ){ //One of m and n is zero.
- if( m.Sign() == 0 ){
- r = n; r.ChangeSign(202); // r = -n;
- return r;
- } else return m;
- } else if( s < 0 ){//diffrent sign
- r = n; r.ChangeSign(202); // r = -n;
- return LLAdd(m, r); //The sign is same as that of m and set by LLAdd().
- } else { //same sign
- c = LLCompare(m, n);
-
- if(c > 0) return LLSub(m, n); // m > n
- if(c < 0){ //m<n, m-n = -(n-m)
- r = LLSub(n, m); //r=n-m
- r.ChangeSign(202); // r = -r;
- return r;
- }
- r.SetZero();
- return r; // c = 0 : m = n
- }
- }
slominus.cpp : last modifiled at 2016/05/01 10:16:55(1,131 bytes)
created at 2017/10/07 10:26:50
The creation time of this html file is 2017/11/09 14:52:03 (Thu Nov 09 14:52:03 2017).